<?php
/**
 * Created by PhpStorm.
 * User: wq
 * Date: 2021/5/21
 * Time: 16:47
 */

namespace App\Utils;

use AlibabaCloud\SDK\Dysmsapi\V20170525\Dysmsapi;
use AlibabaCloud\SDK\Dysmsapi\V20170525\Models\SendSmsRequest;
use Darabonba\OpenApi\Models\Config;

class SMS
{

    /**
     * 阿里大鱼短信发s送
     * @return Dysmsapi
     */
    public static function createClient(){
        $config = new Config([
            "accessKeyId" => env('OSS_ACCESS_KEY'),
            "accessKeySecret" => env('OSS_ACCESS_SECRET')
        ]);
        // 访问的域名
        $config->endpoint = "dysmsapi.aliyuncs.com";
        return new Dysmsapi($config);
    }

    public static function sendSms($mobile,$templateCode,$code){
        $client = self::createClient();
        $sendSmsRequest = new SendSmsRequest([
            "phoneNumbers" => $mobile,
            "signName" => "星迷书海",
            "templateCode" => $templateCode,
            "templateParam" => json_encode(['code'=>$code])
        ]);
        return $client->sendSms($sendSmsRequest);
    }
}
